package com.bawei.weekone2207a.view

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.bawei.weekone2207a.R
import com.bawei.weekone2207a.route.RouteConfig

/**
 * 作者：赵亮
 * 时间：2024/12/14 9:42
 * 功能：
 */
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun GuidePage(navController: NavController = rememberNavController()) {
    // page的状态
    val state = rememberPagerState {
        3
    }
    // 图片集合
    val list = listOf(
        R.drawable.guide1,
        R.drawable.guide2,
        R.drawable.guide3,
    )
    HorizontalPager(modifier = Modifier.fillMaxSize(), state = state) {
        Image(
            modifier = Modifier
                .fillMaxSize()
                .clickable {
                    if (state.currentPage == list.size - 1) {
                        navController.navigate(RouteConfig.MAIN)
                    }
                },
            painter = painterResource(id = list[state.currentPage]),
            contentDescription = null
        )
    }
}

@Preview
@Composable
fun GuidePagePreview() {
    GuidePage()
}

